#!/usr/bin/env node
const fs=require("fs"),
      src=process.argv[2],
      dst=process.argv[3],//target file
      log=console.log,
      err=console.error;

if(!fs.existsSync(src)) {
    err('%s not exist!', src);
      process.exit(1);

}

if(!fs.statSync(src).isFile()) {
    err('%s is not file!', src);
      process.exit(2);

}

if(typeof dst === 'undefined') {
    err('dst is undefined');
      process.exit(3);

}



let stm=fs.createReadStream(src).pipe(fs.createWriteStream(dst));//copy file to another ;read file and write file
stm.on('close', () => {
    fs.chmodSync(dst, fs.statSync(src).mode);

});

